package com.example.yls.demoa;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import static com.example.yls.demoa.R.layout.stu_item;

/**
 * Created by yls on 2018/10/22.
 */

public class StuAdapter extends RecyclerView.Adapter<StuViewHolder> {


    private Context context;
    private ArrayList<Student> students;

    public StuAdapter(Context context, ArrayList<Student> students) {
        this.context = context;
        this.students = students;
    }


    public StuViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       View view= LayoutInflater.from(context).inflate(R.layout.stu_item,parent,false);

        StuViewHolder viewHolder =new StuViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(StuViewHolder holder, int position) {
        Student s=students.get(position);
        holder.headView.setImageResource(s.getImg_id());
        holder.nameView.setText(s.getName());
        holder.ageView.setText(String.valueOf(s.getAge()));

    }

    @Override
    public int getItemCount() {
        return students.size();
    }
}
